import { Modal } from "antd";
import type { ScmPurchaseDetail } from "@/pages/wms/po/entity";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";

interface PurchaseReceiptMaterialSelectProps {
	open: boolean;
	//业务ID
	poCode?: string;
	onCancel: () => void;
	onOk: (selectedMaterials: ScmPurchaseDetail[]) => void;
}

const PurchaseReceiptMaterialSelect: React.FC<PurchaseReceiptMaterialSelectProps> = ({
	open,
	poCode,
	onCancel,
	onOk,
}) => {
	// 选中的用户
	const [selectedMaterials, setSelectedMaterials] = useState<ScmPurchaseDetail[]>([]);

	// 查询参数
	const params = {
		poCode: poCode,
	};

	const handleOk = () => {
		onOk(selectedMaterials);
	};

	return (
		<Modal title="选择采购单物料" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable
				reportCode="purchase_receipt_material_select"
				params={params}
				selectionType={SelectionType.CHECKBOX}
				onSelectChange={(selectedRows) => {
					setSelectedMaterials(selectedRows);
				}}
			/>
		</Modal>
	);
};

export default PurchaseReceiptMaterialSelect;
